package com.ruoyi.htzj.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.htzj.domain.HtzjStreets;
import com.ruoyi.htzj.domain.bo.HtzjStreetsBo;
import com.ruoyi.htzj.service.HtzjStreetsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.mybatis.core.page.PageQuery;

import jakarta.validation.Valid;

import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/htzj/streets")
public class StreetsController extends BaseController {

    private final HtzjStreetsService htzjStreetsService;

    /**
     * 查询街道列表
     */
    @SaCheckPermission("htzj:streets:list")
    @GetMapping("/list")
    public R<List<HtzjStreets>> list(HtzjStreets streets) {
        return htzjStreetsService.queryList(streets);
    }

    /**
     * 查询街道分页列表
     */
    @SaCheckPermission("htzj:streets:list")
    @GetMapping("/pageList")
    public TableDataInfo<HtzjStreets> pageList(HtzjStreets streets, PageQuery pageQuery) {
        return htzjStreetsService.queryPageList(streets, pageQuery);
    }

    /**
     * 通过id获取街道详情
     */
    @SaIgnore
    @GetMapping("/{id}")
    public R<HtzjStreets> getInfo(@PathVariable Long id) {
        return R.ok(htzjStreetsService.queryById(id));
    }

    /**
     * 添加街道
     */
    @SaCheckPermission("htzj:streets:add")
    @PostMapping
    public R<Void> add(@Valid @RequestBody HtzjStreetsBo htzjStreetsBo) {
        htzjStreetsService.insertStreets(htzjStreetsBo);
        return R.ok();
    }

    /**
     * 修改街道
     */
    @SaCheckPermission("htzj:streets:edit")
    @PutMapping
    public R<Void> edit(@Valid @RequestBody HtzjStreetsBo htzjStreetsBo) {
        htzjStreetsService.updateStreets(htzjStreetsBo);
        return R.ok();
    }

    /**
     * 删除街道
     */
    @SaCheckPermission("htzj:streets:delete")
    @DeleteMapping("/{streetIds}")
    public R<Void> remove(@PathVariable Long[] streetIds) {
        htzjStreetsService.deleteStreetsByIds(streetIds);
        return R.ok();
    }
}
